home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / answers / x-faq / part5 < prev    next >
Encoding:
Text File  |  1993-06-15  |  43.6 KB  |  931 lines

  1. Newsgroups: comp.windows.x,news.answers,comp.answers
  2. Path: senator-bedfellow.mit.edu!enterpoop.mit.edu!news.media.mit.edu!uhog.mit.edu!eddie.mit.edu!news.kei.com!sol.ctr.columbia.edu!usc!elroy.jpl.nasa.gov!swrinde!cs.utexas.edu!uunet!visual!dbl
  3. From: dbl@visual.com (David B. Lewis)
  4. Subject: comp.windows.x Frequently Asked Questions (FAQ) 5/5
  5. Message-ID: <C8o1M6.Gy5@visual.com>
  6. Followup-To: poster
  7. Summary: useful information about the X Window System
  8. Reply-To: faq%craft@uunet.uu.net (X FAQ maintenance address)
  9. Organization: VISUAL, Inc.
  10. Date: Tue, 15 Jun 1993 14:01:18 GMT
  11. Approved: news-answers-request@MIT.Edu
  12. Expires: Sun, 18 Jul 1993 00:00:00 GMT
  13. Lines: 915
  14. Xref: senator-bedfellow.mit.edu comp.windows.x:69169 news.answers:9436 comp.answers:1015
  15.  
  16. Archive-name: x-faq/part5
  17. Last-modified: 1993/06/15
  18.  
  19. ----------------------------------------------------------------------
  20. Subject: 120)  I'm writing a widget and can't use a float as a resource value.
  21.  
  22. Float resources are not portable; the size of the value may be larger than
  23. the size of an XtPointer. Try using a pointer to a float instead; the Xaw
  24. Scrollbar float resources are handled in this way. 
  25.  
  26. ----------------------------------------------------------------------
  27. Subject: 121)  Is this a memory leak in the X11R4 XtDestroyWidget()?!
  28.  
  29. Yes. This is the "unofficial" fix-19 for the X11R4 Destroy.c:
  30.  
  31. *** Destroy.c.1.37    Thu Jul 11 15:41:25 1991
  32. --- lib/Xt/Destroy.c    Thu Jul 11 15:42:23 1991
  33. ***************
  34. *** 1,4 ****
  35. --- 1,5 ----
  36.   /* $XConsortium: Destroy.c,v 1.37 90/09/28 10:21:32 swick Exp $ */
  37. + /* Plus unofficial patches in revisions 1.40 and 1.41 */
  38.   
  39.   /***********************************************************
  40.   Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
  41. ***************
  42. *** 221,239 ****
  43.        */
  44.   
  45.       int i = 0;
  46. !     DestroyRec* dr = app->destroy_list;
  47.       while (i < app->destroy_count) {
  48.       if (dr->dispatch_level >= dispatch_level)  {
  49.           Widget w = dr->widget;
  50.           if (--app->destroy_count)
  51.           bcopy( (char*)(dr+1), (char*)dr,
  52. !                app->destroy_count*sizeof(DestroyRec)
  53.                 );
  54.           XtPhase2Destroy(w);
  55.       }
  56.       else {
  57.           i++;
  58. -         dr++;
  59.       }
  60.       }
  61.   }
  62. --- 222,245 ----
  63.        */
  64.   
  65.       int i = 0;
  66. !     DestroyRec* dr;
  67.       while (i < app->destroy_count) {
  68. +     /* XtPhase2Destroy can result in calls to XtDestroyWidget,
  69. +      * and these could cause app->destroy_list to be reallocated.
  70. +      */
  71. +     dr = app->destroy_list + i;
  72.       if (dr->dispatch_level >= dispatch_level)  {
  73.           Widget w = dr->widget;
  74.           if (--app->destroy_count)
  75.           bcopy( (char*)(dr+1), (char*)dr,
  76. !                (app->destroy_count - i) * sizeof(DestroyRec)
  77.                 );
  78.           XtPhase2Destroy(w);
  79.       }
  80.       else {
  81.           i++;
  82.       }
  83.       }
  84.   }
  85.  
  86. [from Donna Converse, converse@expo.lcs.mit.EDU]
  87.  
  88. ----------------------------------------------------------------------
  89. Subject: 122)+ Is this a memory leak in the X11R4 deletion of work procs?!
  90.  
  91. Apparently the X11R4 NextEvent.c`CallWorkProc fails to properly replace
  92. the work proc record back on the free list correctly.
  93.  
  94.         if (delete) {
  95.             w->next = freeWorkRecs;
  96.             freeWorkRecs = w->next;    /* should be  =w; */
  97.         }
  98.  
  99. ----------------------------------------------------------------------
  100. Subject: 123)  Are callbacks guaranteed to be called in the order registered?
  101.  
  102.     Although some books demonstrate that the current implementation of Xt
  103. happens to call callback procedures in the order in which they are registered, 
  104. the specification does not guarantee such a sequence, and supplemental 
  105. authoritative documents (i.e. the Asente/Swick volume) do say that the order is
  106. undefined.  Because the callback list can be manipulated by both the widget and
  107. the application, Xt cannot guarantee the order of execution.
  108.     In general, the callback procedures should be thought of as operating 
  109. independently of one another and should not depend on side-effects of other
  110. callbacks operating; if a seqence is needed, then the single callback to be 
  111. registered can explicitly call other functions necessary.
  112.  
  113. [4/92; thanks to converse@expo.lcs.mit.edu]
  114.  
  115. ----------------------------------------------------------------------
  116. Subject: 124)  Why doesn't XtDestroyWidget() actually destroy the widget?
  117.  
  118.     XtDestroyWidget() operates in two passes, in order to avoid leaving
  119. dangling data structures; the function-call marks the widget, which is not 
  120. actually destroyed until your program returns to its event-loop. 
  121.  
  122. ----------------------------------------------------------------------
  123. Subject: 125)  How do I query the user synchronously using Xt?
  124.     
  125.     It is possible to have code which looks like this trivial callback,
  126. which has a clear flow of control. The calls to AskUser() block until answer
  127. is set to one of the valid values. If it is not a "yes" answer, the code drops
  128. out of the callback and back to an event-processing loop: 
  129.  
  130.     void quit(Widget w, XtPointer client, XtPointer call)
  131.     {
  132.         int             answer;
  133.         answer = AskUser(w, "Really Quit?");
  134.         if (RET_YES == answer)
  135.             {
  136.             answer = AskUser(w, "Are You Really Positive?");
  137.             if (RET_YES == answer)
  138.                 exit(0);
  139.                 }
  140.     }
  141.  
  142.     A more realistic example might ask whether to create a file or whether 
  143. to overwrite it.
  144.     This is accomplished by entering a second event-processing loop and
  145. waiting until the user answers the question; the answer is returned to the
  146. calling function. That function AskUser() looks something like this, where the 
  147. Motif can be replaced with widget-set-specific code to create some sort of 
  148. dialog-box displaying the question string and buttons for "OK", "Cancel" and 
  149. "Help" or equivalents:
  150.  
  151.   int AskUser(w, string)
  152.         Widget          w;
  153.         char           *string;
  154.   {
  155.         int             answer=RET_NONE;    /* some not-used marker */
  156.         Widget          dialog;            /* could cache&carry, but ...*/
  157.         Arg             args[3];
  158.         int             n = 0;
  159.         XtAppContext    context;
  160.  
  161.         n=0;
  162.         XtSetArg(args[n], XmNmessageString, XmStringCreateLtoR(string,
  163.                 XmSTRING_DEFAULT_CHARSET)); n++;
  164.         XtSetArg(args[n], XmNdialogStyle, XmDIALOG_APPLICATION_MODAL); n++;
  165.         dialog = XmCreateQuestionDialog(XtParent(w), string, args, n);
  166.         XtAddCallback(dialog, XmNokCallback, response, &answer);
  167.         XtAddCallback(dialog, XmNcancelCallback, response, &answer);
  168.         XtAddCallback(dialog, XmNhelpCallback, response, &answer);
  169.         XtManageChild(dialog);
  170.  
  171.         context = XtWidgetToApplicationContext (w);
  172.         while (answer == RET_NONE || XtAppPending(context)) {
  173.                 XtAppProcessEvent (context, XtIMAll);
  174.         }
  175.         XtDestroyWidget(dialog);  /* blow away the dialog box and shell */
  176.         return answer;
  177.   }
  178.  
  179.     The dialog supports three buttons, which are set to call the same 
  180. function when tickled by the user.  The variable answer is set when the user 
  181. finally selects one of those choices:
  182.  
  183.   void response(w, client, call)
  184.         Widget          w;
  185.         XtPointer client;
  186.         XtPointer call;
  187.   {
  188.   int *answer = (int *) client;
  189.   XmAnyCallbackStruct *reason = (XmAnyCallbackStruct *) call;
  190.         switch (reason->reason) {
  191.         case XmCR_OK:
  192.                 *answer = RET_YES;    /* some #define value */
  193.                 break;
  194.         case XmCR_CANCEL:
  195.                 *answer = RET_NO; 
  196.         break;
  197.         case XmCR_HELP:
  198.                 *answer = RET_HELP;
  199.                 break;
  200.         default:
  201.                 return;
  202.         }
  203. }
  204.  
  205. and the code unwraps back to the point at which an answer was needed and
  206. continues from there.
  207.  
  208. [Thanks to Dan Heller (argv@sun.com); further code is in Dan's R3/contrib
  209. WidgetWrap library. 2/91]
  210.  
  211. ----------------------------------------------------------------------
  212. Subject: 126)  How do I determine the name of an existing widget?
  213. I have a widget ID and need to know what the name of that widget is.
  214.  
  215.     Users of R4 and later are best off using the XtName() function, which 
  216. will work on both widgets and non-widget objects.
  217.  
  218.     If you are still using R3, you can use this simple bit of code to do 
  219. what you want. Note that it depends on the widget's internal data structures 
  220. and is not necessarily portable to future versions of Xt, including R4.
  221.  
  222.     #include <X11/CoreP.h>
  223.     #include <X11/Xresource.h>
  224.     String XtName (widget)
  225.     Widget widget;    /* WILL work with non-widget objects */
  226.     {
  227.     return XrmNameToString(widget->core.xrm_name);
  228.     }
  229.  
  230. [7/90; modified with suggestion by Larry Rogers (larry@boris.webo.dg.com) 9/91]
  231.  
  232. ----------------------------------------------------------------------
  233. Subject: 127)  Why do I get a BadDrawable error drawing to XtWindow(widget)?
  234. I'm doing this in order to get a window into which I can do Xlib graphics
  235. within my Xt-based program:
  236.  
  237. > canvas = XtCreateManagedWidget ( ...,widgetClass,...) /* drawing area */
  238. > ...
  239. > window = XtWindow(canvas);    /* get the window associated with the widget */
  240. > ...
  241. > XDrawLine (...,window,...);    /* produces error */
  242.  
  243.     The window associated with the widget is created as a part of the 
  244. realization of the widget.  Using a window id of NULL ("no window") could 
  245. create the error that you describe.  It is necessary to call XtRealizeWidget() 
  246. before attempting to use the window associated with a widget. 
  247.     Note that the window will be created after the XtRealizeWidget() call, 
  248. but that the server may not have actually mapped it yet, so you should also 
  249. wait for an Expose event on the window before drawing into it.
  250.  
  251. ----------------------------------------------------------------------
  252. Subject: 128)  Why do I get a BadMatch error when calling XGetImage?
  253.  
  254. The BadMatch error can occur if the specified rectangle goes off the edge of 
  255. the screen. If you don't want to catch the error and deal with it, you can take
  256. the following steps to avoid the error:
  257.  
  258. 1) Make a pixmap the same size as the rectangle you want to capture.
  259. 2) Clear the pixmap to background using XFillRectangle.
  260. 3) Use XCopyArea to copy the window to the pixmap.
  261. 4) If you get a NoExpose event, the copy was clean. Use XGetImage to grab the
  262. image from the pixmap.
  263. 5) If you get one or more GraphicsExpose events, the copy wasn't clean, and 
  264. the x/y/width/height members of the GraphicsExpose event structures tell you 
  265. the parts of the pixmap which aren't good.
  266. 6) Get rid of the pixmap; it probably takes a lot of memory.
  267.  
  268. [10/92; thanks to Oliver Jones (oj@pictel.com)]
  269.  
  270. ----------------------------------------------------------------------
  271. Subject: 129)  How can my application tell if it is being run under X?
  272.  
  273.     A number of programs offer X modes but otherwise run in a straight
  274. character-only mode. The easiest way for an application to determine that it is
  275. running on an X display is to attempt to open a connection to the X server:
  276.     
  277.     display = XOpenDisplay(display_name);
  278.     if (display)
  279.         { do X stuff }
  280.     else
  281.         { do curses or something else }
  282. where display_name is either the string specified on the command-line following
  283. -display, by convention, or otherwise is (char*)NULL [in which case 
  284. XOpenDisplay uses the value of $DISPLAY, if set].
  285.  
  286. This is superior to simply checking for the existence a -display command-line 
  287. argument or checking for $DISPLAY set in the environment, neither of which is 
  288. adequate. [5/91]
  289.  
  290. ----------------------------------------------------------------------
  291. Subject: 130)  How do I make a "busy cursor" while my application is computing?
  292. Is it necessary to call XDefineCursor() for every window in my application?
  293.  
  294.     The easiest thing to do is to create a single InputOnly window that is 
  295. as large as the largest possible screen; make it a child of your toplevel 
  296. window and it will be clipped to that window, so it won't affect any other 
  297. application. (It needs to be as big as the largest possible screen in case the 
  298. user enlarges the window while it is busy or moves elsewhere within a virtual 
  299. desktop.) Substitute "toplevel" with your top-most widget here (similar code 
  300. should work for Xlib-only applications; just use your top Window):
  301.  
  302.      unsigned long valuemask;
  303.      XSetWindowAttributes attributes;
  304.  
  305.      /* Ignore device events while the busy cursor is displayed. */
  306.      valuemask = CWDontPropagate | CWCursor;
  307.      attributes.do_not_propagate_mask =  (KeyPressMask | KeyReleaseMask |
  308.          ButtonPressMask | ButtonReleaseMask | PointerMotionMask);
  309.      attributes.cursor = XCreateFontCursor(XtDisplay(toplevel), XC_watch);
  310.  
  311.      /* The window will be as big as the display screen, and clipped by
  312.         its own parent window, so we never have to worry about resizing */
  313.      XCreateWindow(XtDisplay(toplevel), XtWindow(toplevel), 0, 0,
  314.          65535, 65535, (unsigned int) 0, 0, InputOnly,
  315.          CopyFromParent, valuemask, &attributes);
  316.  
  317. where the maximum size above could be replaced by the real size of the screen,
  318. particularly to avoid servers which have problems with windows larger than
  319. 32767.
  320.  
  321. When you want to use this busy cursor, map and raise this window; to go back to
  322. normal, unmap it. This will automatically keep you from getting extra mouse
  323. events; depending on precisely how the window manager works, it may or may not
  324. have a similar effect on keystrokes as well.
  325.  
  326. In addition, note also that most of the Xaw widgets support an XtNcursor 
  327. resource which can be temporarily reset, should you merely wish to change the
  328. cursor without blocking pointer events.
  329.  
  330. [thanks to Andrew Wason (aw@cellar.bae.bellcore.com), Dan Heller 
  331. (argv@sun.com), and mouse@larry.mcrcim.mcgill.edu; 11/90,5/91]
  332.  
  333. ----------------------------------------------------------------------
  334. Subject: 131)  How do I fork without hanging my parent X program?
  335.  
  336.     An X-based application which spawns off other Unix processes which 
  337. continue to run after it is closed typically does not vanish until all of its 
  338. children are terminated; the children inherit from the parent the open X 
  339. connection to the display. 
  340.     What you need to do is fork; then, immediately, in the child process, 
  341.         close (ConnectionNumber(XtDisplay(widget)));
  342. to close the file-descriptor in the display information. After this do your 
  343. exec. You will then be able to exit the parent.
  344.     Alternatively, before exec'ing make this call, which causes the file 
  345. descriptor to be closed on exec.
  346.         (void) fcntl(ConnectionNumber(XDisplay), F_SETFD, 1);
  347.  
  348. [Thanks to Janet Anstett (anstettj@tramp.Colorado.EDU), Gordon Freedman 
  349. (gjf00@duts.ccc.amdahl.com); 2/91. Greg Holmberg (holmberg@frame.com), 3/93.]
  350.  
  351. ----------------------------------------------------------------------
  352. Subject: 132)  Can I make Xt or Xlib calls from a signal handler?
  353.  
  354.     No. Xlib and Xt have no mutual exclusion for protecting critical 
  355. sections. If your signal handler makes such a call at the wrong time (which 
  356. might be while the function you are calling is already executing), it can leave
  357. the library in an inconsistent state. Note that the ANSI C standard points
  358. out that behavior of a signal handler is undefined if the signal handler calls
  359. any function other than signal() itself, so this is not a problem specific to
  360. Xlib and Xt; the POSIX specification mentions other functions which may be
  361. called safely but it may not be assumed that these functions are called by 
  362. Xlib or Xt functions.
  363.     You can work around the problem by setting a flag in the interrupt
  364. handler and later checking it with a work procedure or a timer event which
  365. has previously been added.
  366.  
  367.     Note: the article in The X Journal 1:4 and the example in O'Reilly 
  368. Volume 6 are in error.
  369.  
  370. [Thanks to Pete Ware (ware@cis.ohio-state.edu) and Donna Converse 
  371. (converse@expo.lcs.mit.EDU), 5/92]
  372.  
  373. ----------------------------------------------------------------------
  374. Subject: 133)  What are these "Xlib sequence lost" errors?
  375.  
  376.     You may see these errors if you issue Xlib requests from an Xlib error 
  377. handler, or, more likely, if you make calls which generate X requests to Xt or 
  378. Xlib from a signal handler, which you shouldn't be doing in any case. 
  379.  
  380. ----------------------------------------------------------------------
  381. Subject: 134)  How can my Xt program handle socket, pipe, or file input?
  382.  
  383.     It's very common to need to write an Xt program that can accept input 
  384. both from a user via the X connection and from some other file descriptor, but 
  385. which operates efficiently and without blocking on either the X connection or 
  386. the other file descriptor.
  387.     A solution is use XtAppAddInput(). After you open your file descriptor,
  388. use XtAppAddInput() to register an input handler. The input handler will be 
  389. called every time there is something on the file descriptor requiring your 
  390. program's attention. Write the input handler like you would any other Xt 
  391. callback, so it does its work quickly and returns.  It is important to use only
  392. non-blocking I/O system calls in your input handlers.
  393.     Most input handlers read the file descriptor, although you can have an 
  394. input handler write or handle exception conditions if you wish.
  395.     Be careful when you register an input handler to read from a disk file.
  396. You will find that the function is called even when there isn't input pending.
  397. XtAppAddInput() is actually working as it is supposed to. The input handler is 
  398. called whenever the file descriptor is READY to be read, not only when there is
  399. new data to be read. A disk file (unlike a pipe or socket) is almost always 
  400. ready to be read, however, if only because you can spin back to the beginning
  401. and read data you've read before.  The result is that your function will almost
  402. always be called every time around XtAppMainLoop(). There is a way to get the 
  403. type of interaction you are expecting; add this line to the beginning of your 
  404. function to test whether there is new data:
  405.          if (ioctl(fd, FIONREAD, &n) == -1 || n == 0) return;
  406. But, because this is called frequently, your application is effectively in a 
  407. busy-wait; you may be better off not using XtAppAddInput() and instead setting 
  408. a timer and in the timer procedure checking the file for input.
  409.  
  410. [courtesy Dan Heller (argv@ora.com), 8/90; mouse@larry.mcrcim.mcgill.edu 5/91;
  411. Ollie Jones (oj@pictel.com) 6/92]
  412.  
  413. ----------------------------------------------------------------------
  414. Subject: 135)  How do I simulate a button press/release event for a widget?
  415.  
  416.     You can do this using XSendEvent(); it's likely that you're not setting
  417. the window field in the event, which Xt needs in order to match to the widget
  418. which should receive the event.
  419.      If you're sending events to your own application, then you can use 
  420. XtDispatchEvent() instead. This is more efficient than XSendEvent() in that you
  421. avoid a round-trip to the server.
  422.     Depending on how well the widget was written, you may be able to call
  423. its action procedures in order to get the effects you want.
  424.  
  425. [courtesy Mark A. Horstman (mh2620@sarek.sbc.com), 11/90]
  426.  
  427. ----------------------------------------------------------------------
  428. Subject: 136)  Why doesn't anything appear when I run this simple program?
  429.  
  430. > ...
  431. > the_window = XCreateSimpleWindow(the_display,
  432. >      root_window,size_hints.x,size_hints.y,
  433. >      size_hints.width,size_hints.height,BORDER_WIDTH,
  434. >      BlackPixel(the_display,the_screen),
  435. >      WhitePixel(the_display,the_screen));
  436. > ...
  437. > XSelectInput(the_display,the_window,ExposureMask|ButtonPressMask|
  438. >     ButtonReleaseMask);
  439. > XMapWindow(the_display,the_window);
  440. > ...
  441. > XDrawLine(the_display,the_window,the_GC,5,5,100,100);
  442. > ...
  443.  
  444.     You are right to map the window before drawing into it. However, the 
  445. window is not ready to be drawn into until it actually appears on the screen --
  446. until your application receives an Expose event. Drawing done before that will 
  447. generally not appear. You'll see code like this in many programs; this code 
  448. would appear after window was created and mapped:
  449.   while (!done)
  450.     {
  451.       XNextEvent(the_display,&the_event);
  452.       switch (the_event.type) {
  453.     case Expose:     /* On expose events, redraw */
  454.         XDrawLine(the_display,the_window,the_GC,5,5,100,100);
  455.         break;
  456.     ...
  457.     }
  458.     }
  459.  
  460.     Note that there is a second problem: some Xlib implementations don't 
  461. set up the default graphics context to have correct foreground/background 
  462. colors, so this program could previously include this code:
  463.   ...
  464.   the_GC_values.foreground=BlackPixel(the_display,the_screen);    /* e.g. */
  465.   the_GC_values.background=WhitePixel(the_display,the_screen);    /* e.g. */
  466.   the_GC = XCreateGC(the_display,the_window,
  467.                 GCForeground|GCBackground,&the_GC_values);
  468.   ...
  469.  
  470. Note: the code uses BlackPixel and WhitePixel to avoid assuming that 1 is 
  471. black and 0 is white or vice-versa.  The relationship between pixels 0 and 1 
  472. and the colors black and white is implementation-dependent.  They may be 
  473. reversed, or they may not even correspond to black and white at all.
  474.  
  475. Also note that actually using BlackPixel and WhitePixel is usually the wrong 
  476. thing to do in a finished program, as it ignores the user's preference for 
  477. foreground and background.
  478.  
  479. And also note that you can run into the same situation in an Xt-based program
  480. if you draw into the XtWindow(w) right after it has been realized; it may
  481. not yet have appeared.
  482.  
  483. ----------------------------------------------------------------------
  484. Subject: 137)  What is the difference between a Screen and a screen?
  485.  
  486.     The 'Screen' is an Xlib structure which includes the information about
  487. one of the monitors or virtual monitors which a single X display supports. A 
  488. server can support several independent screens. They are numbered unix:0.0,
  489. unix:0.1, unix:0.2, etc; the 'screen' or 'screen_number' is the second digit --
  490. the 0, 1, 2 which can be thought of as an index into the array of available 
  491. Screens on this particular Display connection.
  492.     The macros which you can use to obtain information about the particular
  493. Screen on which your application is running typically have two forms -- one
  494. which takes a Screen and one with takes both the Display and the screen_number.
  495.     In Xt-based programs, you typically use XtScreen(widget) to determine 
  496. the Screen on which your application is running, if it uses a single screen.
  497.     (Part of the confusion may arise from the fact that some of the macros
  498. which return characteristics of the Screen have "Display" in the names -- 
  499. XDisplayWidth, XDisplayHeight, etc.)
  500.     
  501. ----------------------------------------------------------------------
  502. Subject: 138)! Can I use C++ with X11? Motif? XView?
  503.     
  504.     The X11R4/5 header files are compatible with C++. The Motif 1.1 header 
  505. files are usable as is inside extern "C" {...}. However, the definition of
  506. String in Intrinsic.h can conflict with the libg++ or other String class and
  507. needs to be worked around.
  508.  
  509.     Some other projects which can help:
  510.     WWL, a set of C++ classes by Jean-Daniel Fekete to wrap X Toolkit 
  511. widgets, available via anonymous FTP from export.lcs.mit.edu as 
  512. contrib/WWL-1.2.tar.Z [7/92] or lri.lri.fr (129.175.15.1) as pub/WWL-1.2.tar.Z.
  513. It works by building a set of C++ classes in parallel to the class tree of the 
  514. widgets.
  515.     The C++ InterViews toolkit is obtainable via anonymous FTP from 
  516. interviews.stanford.edu. InterViews uses a box/glue model similar to that of 
  517. TeX for constructing user interfaces and supports multiple looks on the user 
  518. interfaces. Some of its sample applications include a WYSIWIG document editor 
  519. (doc), a MacDraw-like drawing program (idraw) and an interface builder 
  520. (ibuild).
  521.     THINGS,  a class library written at the Rome Air Force Base by the 
  522. Strategic Air Command, available as freeware on archive sites.
  523.  
  524.     Motif++ is a public-domain library that defines C++ class wrappers for
  525. Motif 1.1; it adds an "application" class for, e.g., initializing X, and also
  526. integrates WCL and the Xbae widget set. This work was developed by Ronald van 
  527. Loon <rvloon@cv.ruu.nl> based on X++, a set of bindings done by the University 
  528. of Lowell Graphics Research Laboratory. The current sources are available from 
  529. decuac.dec.com (192.5.214.1) as /pub/X11/motif++.21.jul.92.tar.Z; there was
  530. a release 4/93 as well.
  531.  
  532.     Xm++ is a user interface framework for C++ using the Motif and Athena
  533. toolkits.  Source is on export as contrib/Xm++.0.51.tar.Z; or email to 
  534. xmplus@ani.univie.ac.at.
  535.     
  536.     The source code examples for Doug Young's "Object-Oriented Programming 
  537. with C++ and OSF/Motif" [ISBN 0-13-630252-1] do not include "widget wrappers" 
  538. but do include a set of classes that encapsulates higher-level facilities 
  539. commonly needed by Motif- or other Xt-based applications; check export in
  540. ~ftp/contrib/young.c++.tar.Z.
  541.     Rogue Wave offers "View.h++" for C++ programmers using Motif; info:
  542. 1-800-487-3217 or +1 503 754 2311.
  543.     A product called "Commonview" by Glockenspiel Ltd, Ireland (??) 
  544. apparently is a C++-based toolkit for multiple window systems, including PM,
  545. Windows, and X/Motif.
  546.     Xv++ is sold by Qualix (415-572-0200; fax -1300); it implements an 
  547. interface from the GIL files that Sun's OpenWindows Developers Guide 3.0 
  548. produces to Xview wrapper classes in C++.
  549.  
  550.     UIT is a set of C++ classes embedding the XView toolkit; it is intended
  551. for use with Sun's OpenWindows Developers Guide 3.0 builder tool. Sources are 
  552. on export.mit.edu.au as UIT.tar.Z. Version 2 was released 5/28/92.
  553.     
  554.     Also of likely use is ObjectCenter (Saber-C++). And a reasonable
  555. alternative to all of the above is ParcPlace's (formerly Solbourne's) Object 
  556. Interface.
  557.  
  558. [Thanks to Douglas S. Rand (dsrand@mitre.org) and George Wu (gwu@tcs.com);2/91]
  559.  
  560. ----------------------------------------------------------------------
  561. Subject: 139)! Where can I obtain alternate language bindings to X?
  562.  
  563.     Versions of the CLX Lisp bindings are part of the X11 core source 
  564. distributions. A version of CLX is on the R5 tape [10/91]; version 5.0.2 [9/92]
  565. is on export.lcs.mit.edu in /contrib/CLX.R5.02.tar.Z.
  566.  
  567.     The SAIC Ada-X11 bindings are through anonymous ftp in /pub from
  568. stars.rosslyn.unisys.com (128.126.164.2). 
  569.     There is an X/Ada study team sponsored by NASA JSC, which apparently is
  570. working out bindings. Information: xada@ghg.hou.tx.us.
  571.     GNU SmallTalk has a beta native SmallTalk binding to X called STIX (by
  572. Steven.Byrne@Eng.Sun.COM). It is still in its beginning stages, and 
  573. documentation is sparse outside the SmallTalk code itself. The sources are 
  574. available as /pub/gnu/smalltalk-1.1.1.tar.Z on prep.ai.mit.edu (18.71.0.38) or 
  575. ugle.unit.no (129.241.1.97).
  576.     Prolog bindings (called "XWIP") written by Ted Kim at UCLA while
  577. supported in part by DARPA are available by anonymous FTP from
  578. export.lcs.mit.edu:contrib/xwip.tar.Z or ftp.cs.ucla.edu:pub/xwip.tar.Z.
  579. These prolog language bindings depend on having a Quintus-type foreign function
  580. interface in your prolog. The developer has gotten it to work with Quintus and 
  581. SICStus prolog. Inquiries should go to xwip@cs.ucla.edu. [3/90]
  582.     Scheme bindings to Xlib, OSF/Motif, and Xaw are part of the Elk
  583. distribution; version 1.5a on export obsoletes the version on the R5 contrib
  584. tape. 
  585.     x-scm, a bolt-on accessory for Aubrey Jaffer's "scm" Scheme interpreter
  586. that provides an interface to Xlib, Motif, and OpenLook, is now available via 
  587. FTP from altdorf.ai.mit.edu:archive/scm/xscm1.05.tar.Z and 
  588. nexus.yorku.ca:pub/scheme/new/xscm1.05.tar.Z.
  589.  
  590.     Poplog V14.2 is offered by Integral Solutions Ltd. (Phone +44 (0)256
  591. 882028; Fax +44 (0)256 882182; Email isl@integ.uucp); it is an integrated
  592. programming environment consisting of the programming languages Pop-11,
  593. Prolog, Standard ML, and Lisp which are compiled to machine code via a common
  594. virtual machine. Pop-11 provides an interface to the X Toolkit which can be
  595. accessed from all other Poplog languages. The OLIT, Motif, and Athena widget
  596. sets are supported, in addition to the custom Poplog (Xpw) widget set.
  597. High-level Pop-11 libraries allow graph drawing, turtle graphics, and the
  598. simple creation of basic button/menu based interfaces.
  599.  
  600.     Ada bindings to Motif, explicitly, will eventually be made available by
  601. the Jet Propulsion Laboratories, probably through the normal electronic
  602. means.  Advance information can be obtained from dsouleles@dsfvax.jpl.nasa.gov,
  603. who may respond as time permits.
  604.     AdaMotif is a complete binding to X and Motif for the Ada language, for
  605. many common systems; it is based in part upon the SAIC/Unisys bindings and also
  606. includes a UIL to Ada translator. Info: Systems Engineering Research 
  607. Corporation, 1-800-Ada-SERC (well!serc@apple.com).
  608.  
  609.     Also: the MIT Consortium, although not involved in producing Ada
  610. bindings for X, maintains a partial listing of people involved in X and Ada;
  611. information is available from Donna Converse, converse@expo.lcs.mit.edu.
  612.  
  613. ----------------------------------------------------------------------
  614. Subject: 140)  Can XGetWindowAttributes get a window's background pixel/pixmap?
  615.  
  616.     No.  Once set, the background pixel or pixmap of a window cannot be 
  617. re-read by clients.  The reason for this is that a client can create a pixmap,
  618. set it to be the background pixmap of a window, and then free the pixmap. The 
  619. window keeps this background, but the pixmap itself is destroyed.  If you're 
  620. sure a window has a background pixel (not a pixmap), you can use XClearArea() 
  621. to clear a region to the background color and then use XGetImage() to read 
  622. back that pixel.  However, this action alters the contents of the window, and 
  623. it suffers from race conditions with exposures. [courtesy Dave Lemke of NCD 
  624. and Stuart Marks of Sun]
  625.  
  626.     Note that the same applies to the border pixel/pixmap. This is a 
  627. (mis)feature of the protocol which allows the server is free to manipulate the
  628. pixel/pixmap however it wants.  By not requiring the server to keep the 
  629. original pixel or pixmap, some (potentially a lot of) space can be saved. 
  630. [courtesy Jim Fulton, MIT X Consortium]
  631.  
  632. ----------------------------------------------------------------------
  633. Subject: 141)  How do I create a transparent window?
  634.     
  635.     A completely transparent window is easy to get -- use an InputOnly
  636. window. In order to create a window which is *mostly* transparent, you have
  637. several choices:
  638.     - the SHAPE extension first released with X11R4 offers an easy way to
  639. make non-rectangular windows, so you can set the shape of the window to fit the
  640. areas where the window should be nontransparent; however, not all servers 
  641. support the extension.
  642.     - a machine-specific method of implementing transparent windows for
  643. particular servers is to use an overlay plane supported by the hardware.  Note 
  644. that there is no X notion of a "transparent color index".
  645.     - a generally portable solution is to use a large number of tiny 
  646. windows, but this makes operating on the application as a unit difficult.
  647.     - a final answer is to consider whether you really need a transparent
  648. window or if you would be satisfied with being able to overlay your application
  649. window with information; if so, you can draw into separate bitplanes in colors
  650. that will appear properly.
  651.  
  652. [thanks to der Mouse, mouse@lightning.McRCIM.McGill.EDU, 3/92; see also
  653. The X Journal 1:4 for a more complete answer, including code samples for this
  654. last option]
  655.  
  656. ----------------------------------------------------------------------
  657. Subject: 142)  Why doesn't GXxor produce mathematically-correct color values?
  658.  
  659.     When using GXxor you may expect that drawing with a value of black on a
  660. background of black, for example, should produce white. However, the drawing
  661. operation does not work on RGB values but on colormap indices. The color that
  662. the resulting colormap index actually points to is undefined and visually
  663. random unless you have actually filled it in yourself. [On many X servers Black
  664. and White often 0/1 or 1/0; programs taking advantage of this mathematical
  665. coincidence will break.]
  666.     If you want to be combining colors with GXxor, then you should be 
  667. allocating a number of your own color cells and filling them with your chosen
  668. pre-computed values.
  669.     If you want to use GXxor simply to switch between two colors, then you 
  670. can take the shortcut of setting the background color in the GC (graphics 
  671. context) to 0 and the foreground color to a value such that when it draws over 
  672. red, say, the result is blue, and when it draws over blue the result is red. 
  673. This foreground value is itself the XOR of the colormap indices of red and 
  674. blue.
  675.  
  676. [Thanks to Chris Flatters (cflatter@zia.aoc.nrao.EDU) and Ken Whaley 
  677. (whaley@spectre.pa.dec.com), 2/91]
  678.  
  679. ----------------------------------------------------------------------
  680. Subject: 143)  Why does every color I allocate show up as black?
  681.  
  682.     Make sure you're using 16 bits and not 8.  The red, green, and blue 
  683. fields of an XColor structure are scaled so that 0 is nothing and 65535 is 
  684. full-blast. If you forget to scale (using, for example, 0-255 for each color) 
  685. the XAllocColor function will perform correctly but the resulting color is 
  686. usually black. 
  687.  
  688. [Thanks to Paul Asente, asente@adobe.com, 7/91]
  689.  
  690. ----------------------------------------------------------------------
  691. Subject: 144)  Why can't my program get a standard colormap?
  692. I have an image-processing program which uses XGetRGBColormap() to get the 
  693. standard colormap, but it doesn't work. 
  694.  
  695.     XGetRGBColormap() when used with the property XA_RGB_DEFAULT_MAP does 
  696. not create a standard colormap -- it just returns one if one already exists.
  697. Use xstdcmap or do what it does in order to create the standard colormap first.
  698.  
  699. [1/91; from der Mouse (mouse@larry.mcrcim.mcgill.edu)]
  700.  
  701. ----------------------------------------------------------------------
  702. Subject: 145)  Why does the pixmap I copy to the screen show up as garbage? 
  703.  
  704.     The initial contents of pixmaps are undefined.  This means that most
  705. servers will allocate the memory and leave around whatever happens to be there 
  706. -- which is usually garbage.  You probably want to clear the pixmap first using
  707. XFillRectangle() with a function of GXcopy and a foreground pixel of whatever 
  708. color you want as your background (or 0L if you are using the pixmap as a 
  709. mask). [courtesy Dave Lemke of NCD and Stuart Marks of Sun]
  710.  
  711. ----------------------------------------------------------------------
  712. Subject: 146)  How do I check whether a window ID is valid?
  713. My program has the ID of a window on a remote display. I want to check whether
  714. the window exists before doing anything with it.
  715.  
  716.     Because X is asynchronous, there isn't a guarantee that the window 
  717. would still exist between the time that you got the ID and the time you sent an
  718. event to the window or otherwise manipulated it. What you should do is send the
  719. event without checking, but install an error handler to catch any BadWindow 
  720. errors, which would indicate that the window no longer exists. This scheme will
  721. work except on the [rare] occasion that the original window has been destroyed 
  722. and its ID reallocated to another window.
  723.  
  724. [courtesy Ken Lee (klee@synoptics.com), 4/90]
  725.  
  726. ----------------------------------------------------------------------
  727. Subject: 147)  Can I have two applications draw to the same window?
  728.  
  729.     Yes. The X server assigns IDs to windows and other resources (actually,
  730. the server assigns some bits, the client others), and any application that 
  731. knows the ID can manipulate the resource [almost any X server resource, except
  732. for GCs and private color cells, can be shared].
  733.     The problem you face is how to disseminate the window ID to multiple 
  734. applications. A simple way to handle this (and which solves the problem of the
  735. applications' running on different machines) is in the first application to 
  736. create a specially-named property on the root-window and put the window ID into
  737. it. The second application then retrieves the property, whose name it also
  738. knows, and then can draw whatever it wants into the window.
  739.     [Note: this scheme works iff there is only one instance of the first
  740. application running, and the scheme is subject to the limitations mentioned
  741. in the Question about using window IDs on remote displays.]
  742.     Note also that you will still need to coordinate any higher-level 
  743. cooperation among your applications. 
  744.     Note also that two processes can share a window but should not try to 
  745. use the same server connection. If one process is a child of the other, it 
  746. should close down the connection to the server and open its own connection.
  747.  
  748. [mostly courtesy Phil Karlton (karlton@wpd.sgi.com) 6/90]
  749.  
  750. ----------------------------------------------------------------------
  751. Subject: 148)  Why can't my program work with tvtwm or swm?
  752.  
  753.     A number of applications, including xwd, xwininfo, and xsetroot, do not
  754. handle the virtual root window which tvtwm and swm use; they typically return 
  755. the wrong child of root. A general solution is to add this code or to use it in
  756. your own application where you would normally use RootWindow(dpy,screen):
  757.  
  758. /* Function Name: GetVRoot
  759.  * Description: Gets the root window, even if it's a virtual root
  760.  * Arguments: the display and the screen
  761.  * Returns: the root window for the client
  762.  */
  763. #include <X11/Xatom.h>
  764. Window GetVRoot(dpy, scr)
  765. Display        *dpy;
  766. int             scr;
  767. {
  768. Window          rootReturn, parentReturn, *children;
  769. unsigned int    numChildren;
  770. Window          root = RootWindow(dpy, scr);
  771. Atom            __SWM_VROOT = None;
  772. int             i;
  773.  
  774.   __SWM_VROOT = XInternAtom(dpy, "__SWM_VROOT", False);
  775.   XQueryTree(dpy, root, &rootReturn, &parentReturn, &children, &numChildren);
  776.   for (i = 0; i < numChildren; i++) {
  777.     Atom            actual_type;
  778.     int             actual_format;
  779.     long            nitems, bytesafter;
  780.     Window         *newRoot = NULL;
  781.  
  782.     if (XGetWindowProperty(dpy, children[i], __SWM_VROOT, 0, 1,
  783.         False, XA_WINDOW, &actual_type, &actual_format, &nitems,
  784.             &bytesafter, (unsigned char **) &newRoot) == Success && newRoot) {
  785.             root = *newRoot;
  786.             break;
  787.         }
  788.     }
  789.  
  790.     return root;
  791. }
  792.  
  793. [courtesy David Elliott (dce@smsc.sony.com). Similar code is in ssetroot, a
  794. version of xsetroot distributed with tvtwm. 2/91]
  795.  
  796. A header file by Andreas Stolcke of ICSI on export.lcs.mit.edu:contrib/vroot.h 
  797. functions similarly by providing macros for RootWindow and DefaultRootWindow;
  798. code can include this header file first to run properly in the presence of a
  799. virtual desktop.
  800.     
  801. ----------------------------------------------------------------------
  802. Subject: 149)  How do I keep a window from being resized by the user?
  803.  
  804.     Resizing the window is done through the window manager; window managers
  805. can pay attention to the size hints your application places on the window, but 
  806. there is no guarantee that the window manager will listen. You can try setting 
  807. the minimum and maximum size hints to your target size and hope for the best. 
  808. [1/91]
  809.  
  810. ----------------------------------------------------------------------
  811. Subject: 150)  How do I keep a window in the foreground at all times?
  812.  
  813.     It's rather antisocial for an application to constantly raise itself
  814. [e.g. by tracking VisibilityNotify events] so that it isn't overlapped -- 
  815. imagine the conflict between two such programs running.  
  816.     The only sure way to have your window appear on the top of the stack
  817. is to make the window override-redirect; this means that you are temporarily
  818. assuming window-management duties while the window is up, so you want to do 
  819. this infrequently and then only for short periods of time (e.g. for popup 
  820. menus or other short parameter-setting windows).
  821.  
  822. [thanks to der Mouse (mouse@larry.mcrcim.mcgill.edu); 7/92]
  823.  
  824. ----------------------------------------------------------------------
  825. Subject: 151)  How do I make text and bitmaps blink in X?
  826.  
  827.     There is no easy way.  Unless you're willing to depend on some sort of
  828. extension (as yet non-existent), you have to arrange for the blinking yourself,
  829. either by redrawing the contents periodically or, if possible, by playing games
  830. with the colormap and changing the color of the contents.
  831.  
  832. [Thanks to mouse@larry.mcrcim.mcgill.edu (der Mouse), 7/91]
  833.  
  834. ----------------------------------------------------------------------
  835. Subject: 152)  How do I get a double-click in Xlib?
  836.  
  837.     Users of Xt have the support of the translation manager to help 
  838. get notification of double-clicking.
  839.     There is no good way to get only a double-click in Xlib, because the 
  840. protocol does not provide enough support to do double-clicks.  You have to do 
  841. client-side timeouts, unless the single-click action is such that you can defer
  842. actually taking it until you next see an event from the server.  Thus, you 
  843. have to do timeouts, which means system-dependent code.  On most UNIXish 
  844. implementations, you can use XConnectionNumber to get the file descriptor of 
  845. the X connection and then use select() or something similar on that.
  846.     Note that many user-interface references suggest that a double-click
  847. be used to extend the action indicated by a single-click; if this is the case
  848. in your interface then you can execute the first action and as a compromise
  849. check the timestamp on the second event to determine whether it, too, should
  850. be the single-click action or the double-click action.
  851.  
  852. [Thanks to mouse@larry.mcrcim.mcgill.edu (der Mouse), 4/93]
  853.  
  854. ----------------------------------------------------------------------
  855. Subject: 153)  How do I render rotated text?
  856.     
  857.     Xlib intentionally does not provide such sophisticated graphics 
  858. capabilities, leaving them up to server-extensions or clients-side graphics
  859. libraries.
  860.     Your only choice, if you want to stay within the core X protocol, is to
  861. render the text into a pixmap, read it back via XGetImage(), rotate it "by 
  862. hand" with whatever matrices you want, and put it back to the server via 
  863. XPutImage(); more specifically:
  864.     1) create a bitmap B and write your text to it.
  865.     2) create an XYBitmap image I from B (via XGetImage).
  866.     3) create an XYBitmap Image I2 big enough to handle the transformation.
  867.     4) for each x,y in I2, I2(x,y) = I(a,b) where 
  868.         a = x * cos(theta) - y * sin(theta)
  869.         b = x * sin(theta) + y * cos(theta)
  870.     5) render I2
  871.     Note that you should be careful how you implement this not to lose
  872. bits; an algorithm based on shear transformations may in fact be better.
  873.     The high-level server-extensions and graphics packages available for X 
  874. also permit rendering of rotated text: Display PostScript, PEX, PHiGS, and GKS,
  875. although most are not capable of arbitrary rotation and probably do not use the
  876. same fonts that would be found on a printer.
  877.     In addition, if you have enough access to the server to install a font
  878. on it, you can create a font which consists of letters rotated at some
  879. predefined angle. Your application can then itself figure out placement of each
  880. glyph.
  881.  
  882. [courtesy der Mouse (mouse@larry.mcrcim.mcgill.edu), Eric Taylor 
  883. (etaylor@wilkins.bmc.tmc.edu), and Ken Lee (klee@synoptics.com), 11/90;
  884. Liam Quin (lee@sq.com), 12/90]
  885.  
  886.     InterViews (C++ UI toolkit, in the X contrib software) has support for
  887. rendering rotated fonts in X.  It could be one source of example code.
  888. [Brian R. Smith (brsmith@cs.umn.edu), 3/91]
  889.     Another possibility is to use the Hershey Fonts; they are 
  890. stroke-rendered and can be used by X by converting them into XDrawLine 
  891. requests. [eric@pencom.com, 10/91]
  892.  
  893.     The xrotfont program by Alan Richardson (mppa3@syma.sussex.ac.uk) 
  894. (posted to comp.sources.x July 14 1992) paints a rotated font by implementing 
  895. the method above and by using an outline (Hershey) font.
  896.     The xvertext package by Alan Richardson (mppa3@syma.sussex.ac.uk) is a 
  897. set of functions to facilitate the writing of text at any angle.  It is on 
  898. export as contrib/xvertext.5.0.shar.Z. 
  899.  
  900.     O'Reilly's X Resource Volume 3 includes information from HP about
  901. modifications to the X fonts server which provide for rotated and scaled text.
  902.  
  903. ----------------------------------------------------------------------
  904. Subject: 154)  What is the X Registry? (How do I reserve names?)
  905.  
  906.     There are places in the X Toolkit, in applications, and in the X
  907. protocol that define and use string names. The context is such that conflicts
  908. are possible if different components use the same name for different things.
  909.     The MIT X Consortium maintains a registry of names in these domains:
  910. orgainization names, selection names, selection targets, resource types,
  911. application classes, and class extension record types; and several others.
  912.     The list as of 7/91 is in the directory mit/doc/Registry on the R5 
  913. tape; it is also available by sending "send docs registry" to the xstuff mail
  914. server.
  915.     To register names (first come, first served) or to ask questions send 
  916. to xregistry@expo.lcs.mit.edu; be sure to include a postal address for
  917. confirmation.
  918.  
  919. [11/90; condensed from Asente/Swick Appendix H]
  920. ----------------------------------------------------------------------
  921.  
  922.  
  923. David B. Lewis                     faq%craft@uunet.uu.net
  924.  
  925.         "Just the FAQs, ma'am." -- Joe Friday 
  926. -- 
  927. David B. Lewis        Temporarily at but not speaking for Visual, Inc.
  928. day: dbl@visual.com    evening: david%craft@uunet.uu.net
  929.